
package com.compuvest.web;

/**
 *
 * @author vasil
 */

public class ItemsInBasket extends Item implements java.io.Serializable {

    private int totalQuantity = 0;
    private boolean reseller = false;
    private double warranty = 0d;
    private String warrantyDesc = "";

    public ItemsInBasket() {
	this(new Item(), false);
    }

    public ItemsInBasket(final Item item, final boolean reseller) {

	this.setItemID(item.getItemID());
	this.setCategoryID(item.getCategoryID());
	this.setItemName(item.getItemName());
	this.setAccwareCode(item.getAccwareCode());

	this.setPrice(item.getPrice());

	this.setResPrice1(item.getResPrice1());
	this.setResPrice2(item.getResPrice2());
	this.setResQuantity2(item.getResQuantity2());
	this.setResPrice3(item.getResPrice3());
	this.setResQuantity3(item.getResQuantity3());

	this.setQuantity(item.getQuantity());
	this.setWeight(item.getWeight());
	this.setStock(item.getStock());
	this.setMfrNumber(item.getMfrNumber());
	this.setCondition(item.getCondition());

	this.setWarrantyMask(item.getWarrantyMask());
	this.setWarrantyPrice1(item.getWarrantyPrice1());
	this.setWarrantyPrice2(item.getWarrantyPrice2()); 
	this.setWarrantyPrice3(item.getWarrantyPrice3());

	this.totalQuantity = 1;
	this.reseller = reseller;
    }

    public int getTotalQuantity()				{ return totalQuantity; }
    public void setTotalQuantity(int totalQuantity)		{ this.totalQuantity = totalQuantity; }

    public double getWarrantyPrice() 				{ return warranty; }
    public void setWarrantyPrice(double warranty)		{ this.warranty = warranty; }

    public String getWarrantyDesc() 				{ return warrantyDesc; }
    public void setWarrantyDesc(String warrantyDesc)		{ this.warrantyDesc = warrantyDesc; }

    public double getWarrantyTotal() 				{ return warranty * totalQuantity; }

    public double getSellPrice() {

	double sellPrice;

	if(reseller && getResPrice1() != 0d) {
	    if(getResQuantity3() != 0 && totalQuantity > getResQuantity3() && getResPrice3() != 0d) {
                sellPrice = getResPrice3();
            }
	    else if(getResQuantity2() != 0 && totalQuantity > getResQuantity2() && getResPrice2() != 0d) {
                sellPrice = getResPrice2();
            }
	    else {
                sellPrice = getResPrice1();
            }
	}
	else {
	    sellPrice = getPrice();
	}

	return sellPrice;
    }
}
